<?php
class News extends MY_Model {
	var $table_name = 'news';
	var $primary_key = 'id';	
	function get_list_news($start,$limit)
    {
	   	$query = $this->db->query("SELECT * FROM news ORDER BY id DESC LIMIT $start,$limit");
		return $query->result_array();
        
    }
	function get_last_entries($num = 5,$lang = null)
    {
    	if(!empty($lang)) $this->db->where('language',$lang);
    	$this->db->order_by("date", "desc"); 
        $query = $this->db->get('news', $num);
        return $query->result_array();
    }
    
	function get_row_for_grid($id)
    {   
        $query = $this->db->query("SELECT id,title,url,date,language FROM news WHERE id = $id");
	    //die("SELECT * FROM news ORDER BY $sort $dir LIMIT $start,$limit");
		$data = $query->row_array();
		$data['edit'] = '<a href="'.base_url().'admin/news_management/add_news/'.$data['id'].'"><img src="'.base_url().'public/skin/back-end/images/edit.png"></a>';
	    //$data['detail'] = '<a href="'.base_url().'news/'.$data['id'].'">Detail</a>';
        return $data;
    }
}